from typing import *


class Solution:

    def longestConsecutive(self, nums: List[int]) -> int:
        s = set(nums)
        ans = 0
        for num in nums:
            if (num - 1) not in s:
                cnt = 1
                while num + 1 in s:
                    num += 1
                    cnt += 1
                ans = max(ans,cnt)
        return ans